package liming.tool.handle.net.udp.base;

import liming.tool.handle.net.root.NetReceiveMap;
import liming.tool.handle.net.root.base.Server;
import liming.tool.handle.net.udp.socket.UdpReceiveMap;

public interface UdpServer extends Server, TransformUdp {

    /**
     * 作为服务端运行的逻辑
     *
     * @param request 请求数据
     * @param respond 响应数据
     * @return 是否回发数据
     */
    default boolean doWork(NetReceiveMap request, NetReceiveMap respond) throws Exception {
        return doWork((UdpReceiveMap) transform(request), (UdpReceiveMap) transform(respond));
    }

    /**
     * 作为服务端运行的逻辑，替换掉doWork(NetReceiveMap request, NetReceiveMap respond)
     *
     * @param request 请求数据
     * @param respond 响应数据
     * @return 是否回发数据
     */
    boolean doWork(UdpReceiveMap request, UdpReceiveMap respond) throws Exception;

    @Override
    default NetReceiveMap addReceiveMap(NetReceiveMap netReceiveMap) throws Exception {
        return addReceiveMap((UdpReceiveMap) transform(netReceiveMap));
    }

    /**
     * 向Socket中通过本地提交数据
     *
     * @param udpReceiveMap 需要提交的数据
     * @return 处理后的结果
     */
    UdpReceiveMap addReceiveMap(UdpReceiveMap udpReceiveMap) throws Exception;
}
